package com.bp.hearthealth.pulse.lnapps.bp_db.bp_project

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

/**
 * @author isnoam
 * @package_name Converters
 * @description：
 */
object BpConverters {
    @TypeConverter
    fun fromStringToObjectArrayList(value: String?): ArrayList<String> {
        val listType = object : TypeToken<ArrayList<String?>?>() {}.type
        return Gson().fromJson(value, listType)
    }

    @TypeConverter
    fun fromArrayListToString(list: ArrayList<String?>?): String {
        val gson = Gson()
        return gson.toJson(list)
    }

    @TypeConverter
    fun fromBooleanToInt(value: Boolean): Int {
        return if (value) 1 else 0
    }

    @TypeConverter
    fun formIntToBoolean(value: Int): Boolean {
        return value != 0
    }
}
